// 生成首页路由
export function generateIndexRouter (data) {
  let indexRouter = []
  return [...indexRouter, ...generateChildRouters(data)]
}

// 生成嵌套路由（子路由）
function generateChildRouters (data) {
  const routers = []
  for (var item of data) {
    let hasChildren = item.children && item.children.length
    if (item.parentId === '0') {
      item.name = item.menuName
      item.url = item.menuRoute
      item.frontPath = 'Layout/AppContent'
    }
    item.redirect = hasChildren ? item.children[0].url : ''
    let component = 'views/' + item.frontPath
    let menu = {
      path: item.url,
      name: item.url,
      hidden: item.isEnable === 0,
      redirect: item.redirect,
      component: resolve => require(['@/' + component + '.vue'], resolve),
      meta: {
        title: item.name,
        icon: item.picUrl,
        url: item.thdUrl
      }
    }
    if (hasChildren > 0) {
      menu.children = [...generateChildRouters(item.children)]
    }
    routers.push(menu)
  }
  return routers
}
